import cv2
import numpy as np

if __name__ == '__main__':
    # 1. 图片输入
    image_np = cv2.imread('work1.jpg')
    # image_gray = cv2.cvtColor(image_np, cv2.COLOR_BGR2GRAY)
    x_min, x_max = 870, 2120
    y_min, y_max = 350, 3610
    ROI_image = image_np.copy()[y_min:y_max, x_min:x_max]
    line_width = 2
    cv2.rectangle(image_np, (x_min, y_min), (x_max, y_max), (0, 0, 255), line_width)
    image_gray = cv2.cvtColor(ROI_image, cv2.COLOR_BGR2GRAY)
    # no_noise_image = cv2.bilateralFilter(image_gray, 7, 50, 50)
    _,image_thresh = cv2.threshold(image_gray, 150, 255,  cv2.THRESH_OTSU + cv2.THRESH_BINARY_INV)
    edges_image = cv2.Canny(image_thresh, 10, 40)
    # cv2.imshow('', image_np)
    cv2.imshow('', edges_image)
    cv2.imwrite('zuoye1.jpg', edges_image)
    cv2.imwrite('zuoye.jpg', image_np)
    cv2.waitKey(0)

